package cn.edu.ujn.lab3.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.ujn.lab3.dao.BaseDict;
import cn.edu.ujn.lab3.dao.BaseDictMapper;
import cn.edu.ujn.lab3.service.BaseDictService;
import cn.edu.ujn.lab3.util.Page;

@Service
public class BaseDictServiceImpl implements BaseDictService {

    @Autowired
    private BaseDictMapper basicDictMapper;
    
    
    @Override
    public List<BaseDict> findBaseDictByTypeCode(String typecode) {
        return basicDictMapper.selectBaseDictByTypeCode(typecode);
    }


    
    @Override
    public Page<BaseDict> findDictList(Integer page, Integer rows, String dictTypeName) {
        BaseDict dict = new BaseDict();
        if(StringUtils.isNotBlank(dictTypeName)) {
            dict.setDictTypeName(dictTypeName);
        }
        // 当前页
        dict.setStart((page-1) * rows) ;
        // 每页数
        dict.setRows(rows);
        List<BaseDict> dictList = basicDictMapper.findDictList(dict);
        Integer count = basicDictMapper.findDictListCount(dict);
        // 创建Page返回对象
        Page<BaseDict> result = new Page<>();
        result.setPage(page);
        result.setRows(dictList);
        result.setSize(rows);
        result.setTotal(count);
        return result;
    }



    @Override
    public int create(BaseDict dict) {
        return basicDictMapper.insert(dict);
    }



    @Override
    public BaseDict getById(String id) {
        return basicDictMapper.selectByPrimaryKey(id);
    }



    @Override
    public int update(BaseDict dict) {
        return basicDictMapper.updateByPrimaryKey(dict);
    }



    @Override
    public int delete(String id) {
        return basicDictMapper.deleteByPrimaryKey(id);
    }
    
    
    

}





